const qcloud = require('../../vendor/qcloud-weapp-client-sdk/index.js')
const config = require('../../config.js')
const app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    offsetH:0,
    avatarUrl:'',
    level:'',
    levelStars:'',
    qualifyingNames:'',
    curClass:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getPersonageLevel(options.uId)
    this.setData({
      qualifyingNames: app.globalData.qualifyingNames
    })
    wx.getSystemInfo({
      success: (res) => {
        this.setData({
          offsetH: res.windowHeight -152
        })
      }
    })
  },

  getPersonageLevel(uId) {
    qcloud.request({
      url: config.service.obtainQualifyingPersonRanking,
      method: "POST",
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      login: true,
      data: {
        'uId': uId,
        'rUId': uId
      },
      success: (response) => {
        let data = response.data
        let iarr = ['zero', 'one', 'two', 'three']
        if (data.code === 0) {
          this.setData({
            avatarUrl: data.qualifyingUserStatDTO['avatarUrl']
          })

          this.setData({
            level: Number(data.qualifyingUserStatDTO['level'])
          })
          let levelStars = data.qualifyingUserStatDTO['levelStars']

          this.setData({
            levelStars
          })
          levelStars = levelStars > 3 ? 3 : levelStars
          this.setData({
            curClass: iarr[levelStars]
          })
        }
      },
      fail: function (err) {
        console.log(err);
      }
    })
  }
})